#include "NormalEnemyAI.h"

#include "Land.h"
#include "Balloon.h"
#include "Hero.h"


NormalEnemyAI::NormalEnemyAI()
{
}

NormalEnemyAI::~NormalEnemyAI()
{
}

//-------------------------------- attack hero -------------------------------------------
b2Vec2 NormalEnemyAI::normalAttack()
{
    // avoid trap first
    PhysicObject *trap = NULL;
    b2Vec2 trapPos;

    for (unsigned int i = 0; i < trapList->count(); ++i) {
        trap = (PhysicObject*)trapList->objectAtIndex(i);
        trapPos = trap->physicBody->GetWorldCenter();

        if ((trapPos.y < this->enemyPos.y && trapPos.y > this->heroPos.y)
                || (trapPos.y > this->enemyPos.y && trapPos.y < heroPos.y)) {
            return this->findBestDirection();
        }
    }

    // avoid hero on top
    if (this->contactRegion < LEFT_REGION) {
        return this->avoidHero();
    }

    // bump hero
    float32 x, y;
    x = heroPos.x - enemyPos.x;
    y = heroPos.y - enemyPos.y;

    return getVectorDirection(x, y);
}

void NormalEnemyAI::attackHero()
{
    this->checkAttackCondition();
    enemyInstance->characterFly(this->normalAttack());
}
